package com.my.study.utils;

import sun.misc.Unsafe;

import java.lang.reflect.Field;

/**
 * @author: yidujun
 * @create: 2022/04/29 16:23
 */
public class UnsafeUtils {

    private static final Unsafe UNSAFE;

    static {
        Field f;
        try {
            f = Unsafe.class.getDeclaredField("theUnsafe");
            f.setAccessible(true);
            UNSAFE = (Unsafe) f.get((Object) null);
        } catch (NoSuchFieldException | IllegalAccessException e) {
            throw new RuntimeException("UNSAFE初始化错误!");
        }
    }

    private UnsafeUtils() {
    }

    public static Unsafe getUnsafe() {
        return UNSAFE;
    }
}
